package com.qf.strategy.service.Impl;

import com.qf.strategy.feign.CacheService;
import com.qf.strategy.service.FilterChain;
import com.qf.strategy.utils.IKAnalyzerUtil;
import com.qianfeng.smsplatform.common.constants.CacheConstants;
import com.qianfeng.smsplatform.common.model.Standard_Submit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 徐老板
 * @date 2020/2/27   17:49
 */
@Service
public class SmsKeyWordFilter implements FilterChain {
    private static final Logger LOGGER = LoggerFactory.getLogger(SmsKeyWordFilter.class);
    @Resource
    CacheService cacheService;

    @Override
    public boolean dealSms(Standard_Submit submit)  {
        LOGGER.error("SmsKeyWordFilter:{}",submit);
        try {
            List<String> segment = IKAnalyzerUtil.segment(submit.getMessageContent());
            LOGGER.error("分词内容是{}",segment);
            for (String string : segment) {
                String result = cacheService.get(CacheConstants.CACHE_PREFIX_DIRTYWORDS + string);
                if (!StringUtils.isEmpty(result)){

                    //TODO 发送数据到es

                    return false;
                }
            }
            LOGGER.error("用户信息中没有敏感词");
            return true;

        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}
